<template>
	<view class="container" @click="save">
		<tki-qrcode v-if="ifShow" cid="qrcode1" ref="qrcode" :val="val" :size="size" :unit="unit" :background="background" :foreground="foreground" :pdground="pdground" :icon="icon" :iconSize="iconsize" :lv="lv" :onval="onval" :loadMake="loadMake" :usingComponents="true" @result="qrR"  style="position: fixed;bottom: 34vh;right: 28%;"/>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
import ayQrcode from "@/components/ay-qrcode/ay-qrcode.vue"
	import tkiQrcode from '@/components/tki-qrcode/tki-qrcode.vue'
	export default {

		data() {
			return {
				userinfo:'',
				modal_qr: false,
				url:'' ,
				ifShow: true,
				val: '', // 要生成的二维码值
				size: 330, // 二维码大小
				unit: 'upx', // 单位
				background: 'black', // 背景色
				foreground: 'white', // 前景色
				pdground: 'white', // 角标色
				icon: '../../static/64.jpg', // 二维码图标
				iconsize: 30, // 二维码图标大小
				lv: 1, // 二维码容错级别 ， 一般不用设置，默认就行
				onval: false, // val值变化时自动重新生成二维码
				loadMake: true, // 组件加载完成后自动生成二维码
				src: '' ,// 二维码生成后的图片地址或base64
				extensionImg: "",
				
			}
		},
		onLoad() {
			
		},
		onShow() {
			
			const res=  uni.getStorage({
			    key: 'userInfo',
			    success: (res)=> {
					
					if(res.data){
						//console.log(res.data,'ssssss')
			     this.userinfo=res.data
				 if(this.userinfo.member_id){
				 //this.getuseragain();
				this.val="http://pth5.njkw668.com/#/pages/user/user?&pid="+this.userinfo.member_id+"&&"
				//this. val="http://pth5.njkw668.com/#/pages/user/user?&pid="
				 }
				 }
				 else{
					 window.location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9a8339b68f86cd01&redirect_uri=http%3A%2F%2Fpth5.njkw668.com%2F%23%2Fpages%2Fpublic%2Flogin&response_type=code&scope=snsapi_userinfo&state=0#wechat_redirect';
				 }
			    },
				fail: (res)=> {
				window.location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9a8339b68f86cd01&redirect_uri=http%3A%2F%2Fpth5.njkw668.com%2F%23%2Fpages%2Fpublic%2Flogin&response_type=code&scope=snsapi_userinfo&state=0#wechat_redirect';
				}
			});
		},
onReady() {
		          
		        },
		computed: {
			...mapState(['hasLogin'])
		},
		methods: {
			code() {
				uni.downloadFile({
					url:this.url,
					success: (res) => { 
						console.log(res.tempFilePath)
						// 获取到图片本地地址后再保存图片到相册(因为此方法不支持远程地址)
						uni.saveImageToPhotosAlbum({
							filePath: res.tempFilePath,
							success: () => {
								uni.showToast({
									title: "保存成功！"
								})
							},
							fail: (err) => {
								console.log(err)
							}
						})
					}
				})
			},
			
			
			save() {
				uni.showActionSheet({
					itemList: ["保存到相册"],
					success: res => {
						if (res.tapIndex == 0) {
							uni.downloadFile({
								url: this.extensionImg,
								success: (res) => {
									if (res.statusCode === 200) {
										uni.saveImageToPhotosAlbum({
											filePath: res.tempFilePath,
											success: res => {
												uni.showToast({
													title: "保存成功！"
												})
											}
										})
									}
								}
							});
						}
					}
				})
			},
		}
	}
</script>

<style lang='scss'>
	.container {
		width: 100%;
		height: 100vh;
		background-image: url('../../static/sharebackground3.jpg');
		background-repeat: no-repeat;
		background-size: 100% 100%;
flex-direction: column;
		.extension_erweima {
			width: 350upx;
			height: 350upx;
			position: relative;
			top: 100upx;
			left: 100upx;
		}
	}
</style>
